import {Component, OnInit} from '@angular/core';
import {ActivatedRoute} from "@angular/router";
import {HttpClient} from "@angular/common/http";
import {TokenService} from "../token.service";

@Component({
  selector: 'app-category-detail',
  templateUrl: './category-detail.component.html',
  styleUrls: ['./category-detail.component.css']
})
export class CategoryDetailComponent implements OnInit {

  constructor(private route: ActivatedRoute, private http: HttpClient, private tokenService: HttpClient) {
  }

  ngOnInit() {
    this.getCategory();
  }

  category;

  getCategory() {
    const id = +this.route.snapshot.paramMap.get('id');
    console.log(id);
    this.tokenService.get('http://193.112.113.194:8769/store/category/' + id)
      .subscribe(hero => this.category = hero['retval']);
  }

  value = '';

  onEnter(value: string, value2: string) {
    this.value = value;
    console.log(value+value2);
    this.tokenService.post('http://127.0.0.1:8769/store/category/' + value2, {'cname': value}).subscribe(
      () => {
        location.href = '/store';
      }
    )

  }
}
